/**
 * 启动
 * @param ip 服务器ip
 * @param projectName 项目名
 * @param remotePath 远程文件目录
 * @param fileName 文件名
 */
void call(String ip, String java, String javaOps, String fileName,String projectName,String remotePath) {
    fileName = "${remotePath}${fileName}"
    withCredentials([sshUserPrivateKey(
            credentialsId: 'ssh_key',  // 凭证 ID
            keyFileVariable: 'SSH_KEY',
            usernameVariable: 'USER'
    )]) {
//      创建日志目录
        ssh.sshVoid(ip, "  mkdir -p ${remotePath}logs")
        // 备份旧日志文件（如果存在）
        ssh.sshVoid(ip, "  [ -f ${remotePath}logs/app.out ] && mv ${remotePath}logs/app.out ${remotePath}logs/app.out.\$(TZ='Asia/Shanghai' date +%Y%m%d_%H%M%S) || true")

        String shell=" cd ${remotePath}  &&  exec  nohup ${java} ${javaOps}   -jar ${fileName}  --spring.profiles.active=prod  --spring.config.additional-location=file:${remotePath}config/ > ${remotePath}logs/app.out  2>&1  < /dev/null & disown ";
        ssh.sshVoid(ip,shell)

//      先睡20s 等待服务启动
        sleep(20)
        for (int i = 1; i <= 60; i++) {
            def PID=  ssh.getPid(ip,projectName)
            if( util.strIsBlack(PID)){
                println("${projectName}服务尚未启动")
            }else{
                println("${projectName}服务已启动  pid:${PID}")
                return
            }
//                 睡眠1秒
            sleep(1)
        }
        def choice  = input(
                message: '是否启动备份文件',
                parameters: [
                        choice(name: 'ACTION',
                                choices: ['启动备份文件', '终止流程'],
                                description: '请选择要执行的操作')
                ],
                submitter: 'admin,developers',  // 允许提交的用户/角色
                ok: '确认'  // 按钮文本
        )
        if ("启动备份文件".equals(choice)) {
            String fileNameBak= fileBak.getFileBakName("${fileName}")
             shell=" cd ${remotePath}  &&  exec  nohup ${java} ${javaOps}   -jar ${fileNameBak}  --spring.profiles.active=prod  --spring.config.additional-location=file:${remotePath}config/ > ${remotePath}logs/app.out  2>&1  < /dev/null & disown ";
            ssh.sshVoid(ip,shell)

        }else{
            error "终止流程"
        }

    }


}

